package com.dshore.messagecenter.dao.system;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;

import com.dshore.messagecenter.model.system.SysMessageLog;
import com.dshore.messagecenter.util.UUIDUtil;

@Repository
public class SysMessageLogDao {
	
	@Autowired
	private JdbcTemplate jdbcTemplate;

	/**
	 * 消息日志添加
	 * @param list
	 */
	public int[] add(List<SysMessageLog> sysMessageLogs) {
		String sql="insert into T_SYS_MESSAGE_LOG(ID,MESSAGE_ID,LOG_TYPE,LOG_DESCRIP,LOG_TIME,EXCHANGE,ROUTING_KEY,CREATED_TIME) values(?,?,?,?,?,?,?,?)";
		List<Object[]> records = new ArrayList<Object[]>();
		Date now = new Date();
		for(SysMessageLog sysMessageLog:sysMessageLogs) {
			records.add(new Object[]{UUIDUtil.getUUId(),sysMessageLog.getMessageId(),sysMessageLog.getLogType(),sysMessageLog.getLogDescrip(),
					sysMessageLog.getLogTime(),sysMessageLog.getExchange(),sysMessageLog.getRoutingKey(),now});
		}
		return jdbcTemplate.batchUpdate(sql, records);
		
	}
}
